<?php
/*!
 * LostKids PHP Library v0.1 
 * http://huali.li/
 *
 * Copyright 2011, 
 * Written By James Pang
 *  
 * Date: 2011/2/14
 */

/**
 * with several adapters for srcs.
 */
class MsgSrcAdaptorImpl implements MsgSrcAdaptor
{
    private $plugins;

    public function __construct() {
    	$this->plugins = Assembly::getPlugins('MsgSrcPlugin', true);
    }

    public function retrieveMsgs() {
        $retMsgs = array();
        foreach ( $this->plugins as $key => $plugin ) {
            $arr = $plugin->retrieveMsgs($key, app_maxRetrieveMsgs);
            if(count($arr) > 0)
        	$retMsgs = array_merge($retMsgs, $arr);
            if(count($retMsgs) > app_maxRetrieveMsgs)
                break;
        }
        return $retMsgs;
    }


    public function replyMsg($msg, $text, $withUrl = false) {
        $msgSrc = $this->plugins[$msg->getDataSrcKey()];
        $msgSrc->respondMsg($msg->getMsgId(), $msg->getOwnerId(), $text, $withUrl);
    }
}
?>
